<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
class ArticleController extends Controller{
    public $layout='column2';  
    public function actionIndex(){
        $chapter=  empty($_REQUEST['chapter'])?'':$_REQUEST['chapter'];
        $verse= empty($_REQUEST['verse'])?'':$_REQUEST['verse'];
        $entry= empty($_REQUEST['entry'])?'':$_REQUEST['entry'];
        $data=array();
        $key='';
        $chapterlist=array();
        $chapters= Chapter::model()->findAll('state=1 order by sequence asc');
        $chapterlist[]='请选择,您要查看的章名称';
        foreach ($chapters as $cr){
            $chapterlist[$cr->id]=  Yii::app()->params['chapter'][$cr->sequence].' '.$cr->name;
        }
        if(!empty($chapter) && !empty($verse) && !empty($entry)){
//            $model =  Entry::model()->findAll('chapter_id=:chapter and verse_id=:verse_id',array(':chapter'=>$chapter,':verse'=>$verse));
            $sql="select * from article where chapter_id=$chapter and verse_id=$verse and entry_id = $entry";
            $data=  Yii::app()->db->createCommand($sql)->queryAll($sql);
        }
        $this->render('index',array('data'=>$data,'chapterlist'=>$chapterlist,'key'=>$key));
    }
    public function actionCreate(){
        $model = new Article();
        $chapterlist=array();
        $chapter= Chapter::model()->findAll('state=1 order by sequence asc');
        $chapterlist[]='请选择,您要查看的章名称';
        foreach ($chapter as $cr){
            $chapterlist[$cr->id]=  Yii::app()->params['chapter'][$cr->sequence].' '.$cr->name;
        }
        if(isset($_POST['Article'])){
            $model->attributes=$_POST['Article'];
            if($model->validate() && $model->save()){
                $this->redirect($this->createUrl('/entry/index',array('chapter'=>$model->chapter_id,'verse'=>$model->verse_id)));
            } 
        }
        $this->render('_form',array('model'=>$model,'chapter'=>$chapterlist));
    }
    public function actionCreate1(){
        $model = new Article();
        $chapterlist=array();
        $chapter= Chapter::model()->findAll('state=1 order by sequence asc');
        $chapterlist[]='请选择,您要查看的章名称';
        foreach ($chapter as $cr){
            $chapterlist[$cr->id]=  Yii::app()->params['chapter'][$cr->sequence].' '.$cr->name;
        }
//        if(isset($_POST['Article'])){
//            $model->attributes=$_POST['Article'];
//            if($model->validate() && $model->save()){
//                $this->redirect($this->createUrl('/entry/index',array('chapter'=>$model->chapter_id,'verse'=>$model->verse_id)));
//            } 
//        }
//        Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . "/js/ueditor/ueditor.config.js",CClientScript::POS_HEAD); 
//        Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . "/js/ueditor/ueditor.all.min.js",CClientScript::POS_HEAD);
//        Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . "/js/ueditor/zh-cn.js",CClientScript::POS_HEAD);
        $this->render('_form_1',array('model'=>$model,'chapter'=>$chapterlist));
    }
}
